//
// Created by chaofengan on 23-8-29.
//

#ifndef UNTITLED6_LOG_SYSTEM_H
#define UNTITLED6_LOG_SYSTEM_H

#include "string"
#include "vector"
#include "ctime"
#include "memory"
#include "iostream"
#include "single_memory_using_record.h"
#include "process_using_table.h"
class memory_use_log{
public:
    std::vector<single_memory_using_record> used_logs;

public:
    void add_apply_log(int pid,int using_amount,int using_position){
        std::shared_ptr<single_memory_using_record> a_log(new single_memory_using_record(pid, APPLY, using_amount, using_position));
        a_log->set_time(get_now_time());
        used_logs.push_back(*a_log);

    }
    void add_release_log(int pid,int memory_position,process_using_table &total_using_table){
        int using_amount = total_using_table.get_amount_by_pid_and_position(pid,memory_position);
        std::shared_ptr<single_memory_using_record> a_log(new single_memory_using_record(pid, RELEASE, using_amount, memory_position));
        a_log->set_time(get_now_time());
        used_logs.push_back(*a_log);
    }
    void show_all(){
        std::cout << "here are memory-using logs:" << std::endl;

        for(auto iter = used_logs.begin();iter != used_logs.end();iter++){
            iter->show();
        }
    }
private:
    std::string get_now_time(){
        time_t now_time = time(nullptr);
        return ctime(&now_time);
    }

};
#endif //UNTITLED6_LOG_SYSTEM_H
